﻿@using Hetang.Models.ControlExtensions
@using Hetang.Models.Interface
@using Hetang.Models.Repository
@model Hetang.Models.DataContext.tbl_Job
@{
    ViewBag.Title = "修改招聘信息";
    ViewBag.SettingTitle = "修改招聘信息 <small class='muted'>( <span class='text-error'>*</span> 为必填项)</small>";
    Layout = "~/Views/Shared/_UserLayout.cshtml";

    IDatabaseRepository _dr = new DatabaseRepository();
    string department = _dr.GetCompanyDepartment();
}

<div class="bs-docs-grid">
    @if (TempData["Info"] != null)
    {
        <div class="alert alert-success fade in auto-hidden" style="width: 750px;">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <strong>@TempData["Info"]</strong>
        </div>
    }
    @if (TempData["Error"] != null)
    {
        <div class="alert alert-error fade in" style="width: 750px;">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <strong>@TempData["Error"]</strong>
        </div>
    }
    <div class="row show-grid">
        <div class="span12">
            @using (Html.BeginForm("editjob", "company", FormMethod.Post, new { @class = "form-horizontal form-publish" }))
            {                
                <div class="control-group">
                    @Html.LabelFor(model => model.JobName, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.EditorFor(model => model.JobName)
                        @Html.ValidationMessageFor(model => model.JobName)
                    </div>
                </div>

                <div class="control-group input-append">
                    @Html.LabelFor(model => model.Department, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        <select id="Department" name="Department">
                            <option value="未分配">未分配</option>
                            @{                
                if (!string.IsNullOrEmpty(department))
                {
                    List<Hetang.Areas.User.Models.DataType.dt_Department> departmentList = Hetang.Models.Helper.JsonHelper.parse<List<Hetang.Areas.User.Models.DataType.dt_Department>>(department);
                    foreach (var d in departmentList)
                    {
                        string selected = "selected";
                                <option value="@d.Name" @(d.Name.Equals(Model.Department) ? selected : "")>@d.Name</option>
                    }
                }
                            }
                        </select>
                        <span class="add-on"><a href="#dpm-box" role="button" data-toggle="modal" title="添加部门">添加部门</a></span>
                    </div>
                </div>

                <div class="control-group input-append">
                    @Html.LabelFor(model => model.Many, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.EditorFor(model => model.Many)
                        <span class="add-on">人</span>
                        @Html.ValidationMessageFor(model => model.Many)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.PostitonType, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        <label class="radio inline">@Html.RadioButtonFor(model => model.PostitonType, "全职", new { @checked = "checked" })全职</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.PostitonType, "兼职")兼职</label>
                        @Html.ValidationMessageFor(model => model.PostitonType)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.WorkPlace, new { @class = "control-label" })
                    <div class="controls">
                        @Html.TextBoxFor(model => model.WorkPlace, new { @class = "span8" })
                        @Html.ValidationMessageFor(model => model.WorkPlace)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Salary, new { @class = "control-label" })
                    <div class="controls">
                        @{
                List<SelectListItem> salary = new List<SelectListItem>()
    {
        new SelectListItem{Text="面议",Value = "面议"},
        new SelectListItem{Text="1000-1800 元",Value = "1000-1800 元"},
        new SelectListItem{Text="1800-2500 元",Value = "1800-2500 元"},
        new SelectListItem{Text="2500-3500 元",Value = "2500-3500 元"},
        new SelectListItem{Text="3500 元以上",Value = "3500 元以上"}
    };
                        }
                        @Html.DropDownListFor(model => model.Salary, salary)
                        @Html.ValidationMessageFor(model => model.Salary)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Learn, new { @class = "control-label" })
                    <div class="controls">
                        @{
                List<SelectListItem> learn = new List<SelectListItem>(){
                        new SelectListItem{Text="小学",Value="小学"},
                        new SelectListItem{Text="初中",Value="初中"},
                        new SelectListItem{Text="高中",Value="高中"},
                        new SelectListItem{Text="中专",Value="中专"},
                        new SelectListItem{Text="大专",Value="大专"},
                        new SelectListItem{Text="本科",Value="本科"},
                        new SelectListItem{Text="硕士",Value="硕士"},
                        new SelectListItem{Text="博士",Value="博士"}
                    };
                        }
                        @Html.DropDownListFor(model => model.Learn, learn)
                        @Html.ValidationMessageFor(model => model.Learn)
                    </div>
                </div>
                
                <div class="control-group input-append">
                    @Html.LabelFor(model => model.English, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        <label class="radio inline">@Html.RadioButtonFor(model => model.English, "无要求", new { @checked = "checked" })无要求</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.English, "一般")一般</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.English, "良好")良好</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.English, "熟练")熟练</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.English, "精通")精通</label>
                        @Html.ValidationMessageFor(model => model.English)
                    </div>
                </div>

                <div class="control-group input-append">
                    @Html.LabelFor(model => model.Age, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.EditorFor(model => model.Age)
                        <span class="add-on">岁或以上</span>
                        @Html.ValidationMessageFor(model => model.Age)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Sex, new { @class = "control-label" })
                    <div class="controls">
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Sex, "男")男</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Sex, "女")女</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Sex, "无要求", new { @checked = "checked" })无要求</label>
                        @Html.ValidationMessageFor(model => model.Sex)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Experiences, new { @class = "control-label" })
                    <div class="controls">
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Experiences, "无需要", new { @checked = "checked" })无需要</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Experiences, "1年以上")1年以上</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Experiences, "2年以上")2年以上</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Experiences, "5年以上")5年以上</label>
                        @Html.ValidationMessageFor(model => model.Experiences)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Contacts, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.TextBoxFor(model => model.Contacts, new { maxlength = 10 })
                        @Html.ValidationMessageFor(model => model.Contacts)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Phone, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.TextBoxFor(model => model.Phone, new { maxlength = 13 })
                        @Html.ValidationMessageFor(model => model.Phone)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Fax, new { @class = "control-label" })
                    <div class="controls">
                        @Html.TextBoxFor(model => model.Fax, new { maxlength = 13 })
                        @Html.ValidationMessageFor(model => model.Fax)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.QQ, new { @class = "control-label" })
                    <div class="controls">
                        @Html.TextBoxFor(model => model.QQ, new { maxlength = 11 })
                        @Html.ValidationMessageFor(model => model.QQ)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Address, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.TextBoxFor(model => model.Address, new { @class = "span11" })
                        @Html.ValidationMessageFor(model => model.Address)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.OtherDemand, new { @class = "control-label", important = "*" })
                    <div class="controls">
                        @Html.TextAreaFor(model => model.OtherDemand, new { style = "width:580px;height:250px;resize:vertical;margin:10px 0;" })
                        <br />
                        @Html.ValidationMessageFor(model => model.OtherDemand)
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(model => model.Urgent, new { @class = "control-label" })
                    <div class="controls">
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Urgent, false, new { @checked = "checked" })否</label>
                        <label class="radio inline">@Html.RadioButtonFor(model => model.Urgent, true)是</label>
                        @Html.ValidationMessageFor(model => model.Urgent)
                    </div>
                </div>

                <div class="control-group">
                    <div class="controls">
                        <button type="submit" class="cbtn cbtn-info">保存</button>
                    </div>
                </div>
            }
        </div>
    </div>
</div>

<div id="dpm-box" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="dpm-box-Label" aria-hidden="true" data-keyboard="false">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>部门管理</h3>
    </div>
    <div class="modal-body">
        <div>
            <h4>已有部门</h4>
            <div class="dpm-list bottom20">
                @{
                    if (!string.IsNullOrEmpty(department))
                    {
                        List<Hetang.Areas.User.Models.DataType.dt_Department> departmentList = Hetang.Models.Helper.JsonHelper.parse<List<Hetang.Areas.User.Models.DataType.dt_Department>>(department);
                        foreach (var d in departmentList)
                        {                                
                        <span class='label label-info'>@d.Name</span>                                
                        }
                    }
                }
            </div>
        </div>
        <div class="add-Dpm">
            @Html.TextBox("dpmName", null, new { style = "margin-bottom: 0px;", placeholder = "输入部门名称进行添加" })
            <input type="button" id="btn-add" class="cbtn cbtn-info" value="添加" />
        </div>
    </div>
    <div class="modal-footer">
        <a href="#" data-dismiss="modal" class="cbtn">关闭</a>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $("#btn-add").click(function () {
            if ($("#dpmName").val() == "") {
                alert('(￣▽￣")别急嘛！先输入部门的名称再按我添加吧！');
                $("#dpmName").focus();
            }
            else {
                $(this).attr("disabled", "disabled");
                $.post("/user/company/adddepartment", { "d": $("#dpmName").val() }, function (data) {
                    if (data == "ok") {
                        $("#Department").append("<option value='" + $("#dpmName").val() + "'>" + $("#dpmName").val() + "</option>");
                        $(".dpm-list").append("<span class='label label-info'>" + $("#dpmName").val() + "</span>");
                        $("#dpmName").val("");
                    }
                    else {
                        alert(data);
                    }
                });
                $(this).removeAttr("disabled");
            }
        });
    });

    setTimeout(function () {
        $(".alert-success").fadeOut(2000);
    }, 5000);
</script>

@Html.GetJavascript("jquery.validate.min.js")
@Html.GetJavascript("jquery.validate.unobtrusive.min.js")
